package cn.pfund.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.pfund.entity.NewsType;
import cn.pfund.service.NewsTypeService;
import cn.pfund.dao.NewsTypeDao;
import cn.pfund.util.Pagination;
import cn.pfund.util.ParamBean;
import cn.pfund.util.QueryCondition;

@Service("newsTypeService")
public class NewsTypeServiceImpl extends BaseServiceImpl implements NewsTypeService {
	@Resource(name="newsTypeDao")
    private NewsTypeDao newsTypeDao;
    
    @Transactional(readOnly = true)
	public Pagination<NewsType> getPagination(ParamBean paramBean) {
		List<QueryCondition> queryConditions = new ArrayList<QueryCondition>();
		if (StringUtils.isNotBlank(paramBean.getKeyword())) {
			queryConditions.add(new QueryCondition(paramBean.getField(), QueryCondition.LK, paramBean.getKeyword()));
		}
		String orderBy = "order by orders asc";
		Pagination<NewsType> pagination = (Pagination<NewsType>)getPagination(NewsType.class, queryConditions, orderBy, paramBean.getPage(), paramBean.getPageSize());
		pagination.setPageHtml(paramBean.getUrl());
		return pagination;
	}

    @Transactional(readOnly = true)
	public List<NewsType> getAllNewsType() {
		String orderBy = "order by orders asc";
		return get(NewsType.class, null, orderBy);
	}
}
